package com.thread.create;

/**
 * 实现Runnable的优点：方便共享资源,共享用例
 * @author jiangbang
 * @date 2016/6/16
 */
public class RunnableImpl04 implements Runnable{
    private int num = 50;

    @Override
    public void run() {
        while(true){
            if(num<=0){
                break;
            }
            System.out.println(Thread.currentThread().getName()+"抢到啦"+num--);
        }
    }


    public static void main(String[] args) {
        //真实角色
        RunnableImpl04 runnableImpl2 = new RunnableImpl04();
        //代理角色
        Thread thread1 = new Thread(runnableImpl2,"路人甲");
        Thread thread2 = new Thread(runnableImpl2,"路人乙");
        Thread thread3 = new Thread(runnableImpl2,"路人丙");
        //启动线程
        thread1.start();
        thread2.start();
        thread3.start();
    }
}
